package model

import (
	"encoding/json"
	"time"
)

type PrivateMessages struct {
	Id       int64    `json:"id" xorm:"not null pk autoincr BIGINT"`
	Mid      int64    `json:"mid" xorm:"BIGINT notnull comment('消息id') index"`
	AppsId   uint      `json:"apps_id" xorm:"INT notnull comment('app id') index"`
	From     int64    `json:"from" xorm:"BIGINT notnull comment('拨号用户id') index"`
	To       int64    `json:"to" xorm:"BIGINT notnull comment('目标id') index"`
	Text     string    `json:"text" xorm:"TEXT comment('消息内容')"`
	TextType byte      `json:"text_type" xorm:"TINYINT notnull default 1 comment('消息类型 1:文字 2:图片 3:语音 4:视频 5:地点 6:链接')"`
	Status   byte      `json:"status" xorm:"TINYINT notnull default 1 comment('消息状态 -1:删除 0:撤回 1:已发送 2:已读')"`
	Created  time.Time `json:"created,omitempty" xorm:"created not null TIMESTAMP"`
	Updated  time.Time `json:"updated,omitempty" xorm:"updated TIMESTAMP"`
}

const MSG_TYPE_IS_TEXT byte = 1
const MSG_TYPE_IS_IMAGE byte = 2
const MSG_TYPE_IS_AUDIO byte = 3
const MSG_TYPE_IS_VIDEO byte = 4

type Multimedia struct {
	Id   int64  `json:"id"`
	Url  string `json:"url"`
	Mime string `json:"mime"`
	Size int64  `json:"size"`
}

func (m PrivateMessages) TableName() string {
	return "private_messages"
}

func (u *PrivateMessages) Marshal() ([]byte, error) {
	return json.Marshal(u)
}

func (u *PrivateMessages) Unmarshal(b []byte) error {
	return json.Unmarshal(b, u)
}
